import subprocess
import threading

# 检测指定IP网络是否通畅
def check_ip(ip):
    ping_cmd = "ping -n 2 -w 1 %s " % ip
    ping_result = subprocess.call(ping_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    if ping_result == 0:
        print("Host 【%s】 is up!!!!!" % ip)

# 检测网段 10.11.0.0/24     10.11.0.1-10.11.0.254
def check_subnet():
    for i in range(1, 255):
        ip = "10.11.0.%s" % i
        # 创建线程，target=函数名，args=(参数1,参数2,...)，元组格式
        ping_thread = threading.Thread(target=check_ip, args=(ip,))
        ping_thread.start()


if __name__ == '__main__':
    check_subnet()